package com.zbkj.admin.controller.platform;

import com.github.pagehelper.PageInfo;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.dal.pojo.request.ba.ConcludeDisplaceRequest;
import com.zbkj.dal.pojo.request.ba.QueryDisplaceRequest;
import com.zbkj.dal.pojo.response.ba.DisplaceDetailResponse;
import com.zbkj.dal.pojo.response.ba.DisplaceResponse;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.service.service.DisplaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author tianzhonghai
 * 2023/10/10 12:17
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/displace")
@Api(tags = "奢品置换")
public class DisplaceController {
    @Autowired
    private DisplaceService displaceService;


    @ApiOperation(value = "分页获取奢品置换信息")
    @RequestMapping(value = "/pageDisplace", method = RequestMethod.POST)
    public CommonResult<CommonPage<DisplaceResponse>> pageDisplace(@RequestBody QueryDisplaceRequest queryDisplaceRequest, PageParamRequest pageParamRequest) {
        if (CollectionUtils.isNotEmpty(queryDisplaceRequest.getTimes())) {
            queryDisplaceRequest.setBeginDate(queryDisplaceRequest.getTimes().get(0));
            queryDisplaceRequest.setEndDate(queryDisplaceRequest.getTimes().get(1));
        }
        PageInfo<DisplaceResponse> sharePageInfo = displaceService.queryDisplace(queryDisplaceRequest, pageParamRequest);
        return CommonResult.success(CommonPage.restPage(sharePageInfo));
    }

    @ApiOperation(value = "奢品置换详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public CommonResult<DisplaceDetailResponse> detail(@PathVariable("id")Integer id) {
        return CommonResult.success(displaceService.detail(id));
    }

    @ApiOperation(value = "确认奢品置换信息")
    @RequestMapping(value = "/confirm", method = RequestMethod.POST)
    public CommonResult<Boolean> confirm(@Validated @RequestBody ConcludeDisplaceRequest confirmRequest) {
        return CommonResult.success(displaceService.confirm(confirmRequest));
    }
}
